{include_core file="m/lib/header.html" title="我的订单" center="center"}
{if $order_list}
<div class="payment js_loadingList">
  {foreach $order_list as $k=>$v}
  <div class="payment-not js_openLink js_orderList" data-href="{AnUrl("order/{$v.id}")}">
    <div class="payment-state clearfix">
      <div class="state-l">{order_config::$dealer_progress[$v.progress]}</div>
      <div class="state-r">
        <p>订单号：<span>{$v.order_code}</span></p> 
          <a href="javascript:void(0);" class="disabled">
            <img src="{$smarty.const.STATIC_URL}/images/m2-images/trash{if $v.progress > 0}-disabled{/if}.png" class="{if $v.progress == 0}js_deleteOrder{else}js_deleteDisabled{/if}" data-order_id="{$v.id}"/>
          </a>
      </div>
    </div>
    <div class="payment-vessle">
      {$order_count = count($v.detail)}
      {foreach $v.detail as $key => $value}
        <h2 class="js_openLink js_goodsInfo" data-href="{AnUrl("goods/{$value.goods_id}")}" data-goods_num="{$value.goods_num}" data-sku_id="{$value.sku_id}" data-is_gift="{$value.is_gift}" data-is_promotion="{$value.is_promotion}"><img src="{_image($value.goods_cover)}" width="92" /></h2>
      {if $order_count == 1}
        <p class="js_openLink" data-href="{AnUrl("goods/{$value.goods_id}")}">{$value.goods_title}</p>
      {/if}
      {/foreach}
    </div>
    <div class="payment-mony clearfix">
      <p class="payment-paying">实付款：￥<span>{$v.price}</span></p>
      {if $v.progress == 1}
      <a class="payment-btn js_openLink" data-href="{order_helper::get_order_pay_url($v.id)}">立即支付</a>
      {elseif $v.progress == 10}
      <p class="payment-old js_cancelOrder" data-order_id="{$v.id}">取消订单</p>
      {elseif $v.progress == 15}
      <a class="payment-btn js_sureReceiver" data-order_id="{$v.id}">确认收货</a>
      {elseif $v.progress == 20}
      <p class="payment-old js_openLink" data-login="1" data-href="{AnUrl("service/slt_service?order_id={$v.id}")}">申请售后</p>
      {elseif $v.progress == 0}
      <a class="payment-old js_replayToCart" href="javascript:void(0);" data-id="{$v.id}">再次购买</a>
      {/if}
    </div>
  </div>
  {/foreach}
</div>
<div class="more-btn"><a href="javascript:void(0);" class="arrow js_loadMore" data-url="{AnUrl('order/load_list')}" data-page_no="1"></a></div>
  <div style="display:none;" class="js_tmpDiv"></div>
{else}
{include_core file="m/lib/dont_have_info.html" info="暂无订单"}
{/if}
<!--我的订单payment  end-->
{load_js file="app/m_load.js"}
<script>
  $(function(){
    /**
     * 确认收货
     */
    $('.js_sureReceiver').on('click',function(e){
      e.preventDefault();
      e.stopPropagation();
      var url = siteUrl+'/order/sure_receive';
      var id = $(this).data('order_id');

      if (btnClick() === false) {
        return false;
      }
      showConfirm('您确定已经收到商品了吗？', function(){
        $.post(url, { id:id }, function(json){
          if (json.info == 'ok') {
            window.location.href = window.location.href;
          } else {
            showMsg(json.info);
          }
          btnClick('reset');
        }, 'json');
      })
    });

    /**
     * 删除订单
     */
    $('body').on('click', '.js_deleteDisabled', function(e){
      e.preventDefault();
      e.stopPropagation();
      showMsg('当前订单不能删除', 1);
    });
    $('body').on('click', '.js_deleteOrder', function(e){
      e.preventDefault();
      e.stopPropagation();
      var orderId = $(this).data('order_id');
      var url = siteUrl+'/order/check_delete';
      var _this = $(this);
      if (btnClick() === false) {
        return false;
      }
      showConfirm('您确定要删除当前订单?', function(){
        $.post(url, { id:orderId }, function(json){
          if (json.info == 'ok') {
            _this.closest('.js_orderList').slideUp();
          } else {
            showMsg(json.info);
          }
          btnClick('reset');
        }, 'json');
      }, function(){
        btnClick('reset');
      });
    });

    /**
     * 再次加入购物车
     */
    $('body').on('click', '.js_replayToCart',function(e){
      e.preventDefault();
      e.stopPropagation();
      var parentLi = $(this).closest('.js_orderList');
      parentLi.find('.js_goodsInfo').each(function(){
        var skuId    = $(this).data('sku_id');
        var goodsNum = $(this).data('goods_num');
        var is_gift  = $(this).data('is_gift');
        var is_promotion = $(this).data('is_promotion');
        if(is_gift == 0 && is_promotion == 0) {
          window.location.href=$(this).data('href');
          return false;
        }
        /* addGoodsToCart(skuId, goodsNum, function(){ }, is_promotion, is_gift); */
      });
      /* showMsg('添加商品到购物车，请稍等...');
      setTimeout(function(){
        location.href = siteUrl+'/cart';
      }, 1000); */
    });

    /**
     * 取消订单
     */
    $('body').on('click', '.js_cancelOrder',function(e){
      e.preventDefault();
      e.stopPropagation();
      var orderId = $('.js_cancelOrder').data('order_id');
      var url     = siteUrl+'/order/cancel_order';
      if (btnClick() === false) {
        return false;
      }
      showConfirm('您确定要取消当前订单吗？', function(){
        $.post(url, { order_id:orderId, reason:'手机取消，暂无选择' }, function(json){
          if (json.info == 'ok') {
            location.href = location.href;
          } else {
            showMsg(json.info, 1);
          }
          btnClick('reset');
        }, 'json');
      }, function(){
        btnClick('reset');
      });
    });
  });
</script>
{include_core file="m/lib/footer.html"  center="center"}